package com.emcom.gotour.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.util.HtmlUtils;

import com.emcom.gotour.dao.TourContentDao;
import com.emcom.gotour.dao.TourSchedulerDao;
import com.emcom.gotour.po.TourContent;
import com.emcom.gotour.po.TourScheduler;

public class TourManageServiceImpl implements TourManageService {

	private TourContentDao tourContentDao;

	private TourSchedulerDao tourSchedulerDao;

	private final static String ALL = "-";

	public List<TourContent> queryMultiContent(String subject, String typeId, String category) {
		TourContent parameters = new TourContent();
		if(!StringUtils.equals(typeId, ALL) && !StringUtils.isEmpty(typeId)) {
			parameters.setTypeId(typeId);
		}
		if(!StringUtils.equals(category, ALL) && !StringUtils.isEmpty(category)) {
			parameters.setCategory(category);
		}
		if(!StringUtils.isEmpty(subject)) {
			parameters.setSubject(subject);
		}
		return tourContentDao.query(parameters);
	}

	public void deleteTour(long id) {
		// Delete Scheduler.<br/>
		TourScheduler tourScheduler = new TourScheduler();
		tourScheduler.setTourId(id);
		tourSchedulerDao.delete(tourScheduler);
		// Delete Tour Content.<br/>
		TourContent tourContent = new TourContent();
		tourContent.setId(id);
		tourContentDao.delete(tourContent);
	}

	public void saveTour(TourContent tourContent) {
		tourContent.setCategory(HtmlUtils.htmlEscape(tourContent.getCategory()));
		tourContent.setSubject(HtmlUtils.htmlEscape(tourContent.getSubject()));
		tourContent.setAim(HtmlUtils.htmlEscape(tourContent.getAim()));
		tourContent.setCharacteristic(HtmlUtils.htmlEscape(tourContent.getCharacteristic()));
		tourContent.setLocation(HtmlUtils.htmlEscape(tourContent.getLocation()));
		tourContent.setCostStandard(HtmlUtils.htmlEscape(tourContent.getCostStandard()));
		tourContent.setCostNotice(HtmlUtils.htmlEscape(tourContent.getCostNotice()));
		tourContent.setAttention(HtmlUtils.htmlEscape(tourContent.getAttention()));
		tourContent.setStatement(HtmlUtils.htmlEscape(tourContent.getStatement()));
		tourContent.setComments(HtmlUtils.htmlEscape(tourContent.getComments()));
		tourContentDao.insert(tourContent);
	}

	public void updateTour(TourContent tourContent) {
		tourContentDao.update(tourContent);
	}

	public void setTourContentDao(TourContentDao tourContentDao) {
		this.tourContentDao = tourContentDao;
	}

	public void setTourSchedulerDao(TourSchedulerDao tourSchedulerDao) {
		this.tourSchedulerDao = tourSchedulerDao;
	}

}
